package com.yxzr.youyou.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.flyco.tablayout.SlidingTabLayout;
import com.yxzr.youyou.PlayRecordActivity;
import com.yxzr.youyou.R;
import com.yxzr.youyou.SearchActivity;
import com.yxzr.youyou.adapter.TablayoutFragmentAdapter;
import com.yxzr.youyou.base.BaseFragment;
import com.yxzr.youyou.fragment.home.ComicFragment;
import com.yxzr.youyou.fragment.home.HomePageFragment;
import com.yxzr.youyou.fragment.home.InformationFragment;
import com.yxzr.youyou.fragment.home.MovieFragment;
import com.yxzr.youyou.fragment.home.TVPlayFragment;
import com.yxzr.youyou.fragment.home.VarietyFragment;
import com.yxzr.youyou.fragment.vip.VipComicFragment;
import com.yxzr.youyou.fragment.vip.VipHomePageFragment;
import com.yxzr.youyou.fragment.vip.VipInformationFragment;
import com.yxzr.youyou.fragment.vip.VipMovieFragment;
import com.yxzr.youyou.fragment.vip.VipTVPlayFragment;
import com.yxzr.youyou.fragment.vip.VipVarietyFragment;

import java.util.ArrayList;

public class VipFragment extends BaseFragment{
    private SlidingTabLayout slidingTabLayout;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private ViewPager mViewPager;
    private ImageView search_iv,playrecord_iv;
    private String[] mTitle = {"首页","电影","电视剧","动漫","综艺"};
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.frag_home,null);
        initView(v);
        return v;
    }
    private void initView(View v) {
        mViewPager = v.findViewById(R.id.viewpager);
        slidingTabLayout = v.findViewById(R.id.slidingTabLayout);
        search_iv = v.findViewById(R.id.search_iv);
        playrecord_iv = v.findViewById(R.id.playrecord_iv);
        mFragments.clear();
        mFragments.add(new VipHomePageFragment());
        mFragments.add(new VipMovieFragment());
        mFragments.add(new VipTVPlayFragment());
        mFragments.add(new VipComicFragment());
        mFragments.add(new VipVarietyFragment());
        mViewPager.setAdapter(new TablayoutFragmentAdapter(getChildFragmentManager(),mTitle,mFragments));
        //关联viewpager
        slidingTabLayout.setViewPager(mViewPager);
        search_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), SearchActivity.class);
                startActivity(intent);
            }
        });

        playrecord_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), PlayRecordActivity.class);
                startActivity(intent);
            }
        });
    }
}
